/*
 * @Date: 2021-09-12 19:21:05
 * @Author: Acckno1
 * @LastEditTime: 2021-09-12 19:23:09
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>

using namespace std;

struct Record{
    int id, c, m, e, a;
    pair<int, char> p;
}record[2010];

int n, m;
// pair.first 成绩 pair.second 学号
vector<pair<int, int>> cc, mm, ee, aa;


int main() {
    // 使用hash表来存放。k：学号 v：record中的索引
    unordered_map<int, int> mp;
    cin >> n >> m;
    for (int i = 0; i < n; i ++) {
        cin >> record[i].id >> record[i].c >> record[i].m >> record[i].e;
        record[i].a =(record[i].c + record[i].m + record[i].e)/ 3.0 + 0.5;
        record[i].p.first = 0x3f3f3f3f;
        cc.push_back({record[i].c, record[i].id});
        mm.push_back({record[i].m, record[i].id});
        ee.push_back({record[i].e, record[i].id});
        aa.push_back({record[i].a, record[i].id});
        mp[record[i].id] = i;
    }
    
    sort(cc.begin(), cc.end(), greater<pair<int, int>>());
    sort(mm.begin(), mm.end(), greater<pair<int, int>>());
    sort(aa.begin(), aa.end(), greater<pair<int, int>>());
    sort(ee.begin(), ee.end(), greater<pair<int, int>>());
    
    // 用哈希表来判断是否有重复的分数，如果有重复的分数，名次不变。
    unordered_map<int, int> g;
    
    g.clear();
    for (int i = 0, r = 1; i < ee.size(); i ++ ) {
        // 如果分数没有出现过，当前名次就是i + 1，在判断某一个人的最好成绩是否优于当前成绩名次
        // 优于即更新
        if (g.find(ee[i].first) == g.end()) g[ee[i].first] = i + 1;
        if (record[mp[ee[i].second]].p.first >= g[ee[i].first]) 
            record[mp[ee[i].second]].p.first = g[ee[i].first], record[mp[ee[i].second]].p.second = 'E';
    }
   
    g.clear();
    for (int i = 0, r = 1; i < mm.size(); i ++ ) {
        if (g.find(mm[i].first) == g.end()) g[mm[i].first] = i + 1;
        if (record[mp[mm[i].second]].p.first >= g[mm[i].first]) 
            record[mp[mm[i].second]].p.first = g[mm[i].first], record[mp[mm[i].second]].p.second = 'M';
    }
    
    g.clear();
    for (int i = 0, r = 1; i < cc.size(); i ++ ) {
        if (g.find(cc[i].first) == g.end()) g[cc[i].first] = i + 1;
        if (record[mp[cc[i].second]].p.first >= g[cc[i].first]) 
            record[mp[cc[i].second]].p.first = g[cc[i].first], record[mp[cc[i].second]].p.second = 'C';
    }
    
    g.clear();
    for (int i = 0, r = 1; i < aa.size(); i ++ ) {
        if (g.find(aa[i].first) == g.end()) g[aa[i].first] = i + 1;
        if (record[mp[aa[i].second]].p.first >= g[aa[i].first]) 
            record[mp[aa[i].second]].p.first = g[aa[i].first], record[mp[aa[i].second]].p.second = 'A';
    }
    
    for (int i = 0; i < m; i ++) {
        int idx;
        cin >> idx;
        if (mp.find(idx) == mp.end()) puts("N/A");
        else {
            cout << record[mp[idx]].p.first << " " << record[mp[idx]].p.second << endl;
        } 
    }
    return 0;
}
